package sketch.issta11.specifystatements;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;


import sketch.specs.annotation.Repl;
import sketch.specs.annotation.Repls;
import sketch.specs.annotation.TestSketch;

import junit.framework.TestCase;

public class Z_ReplaceStatement_Example extends TestCase {
	
	@TestSketch
	@Repl(source={"add"}, dest={"remove"})
	public void testReplacement() {
		List<String> l = new LinkedList<String>();
		l.add("1");
		l.add("2");
	}
	
	@TestSketch
	@Repls(repls = {@Repl(source={"clear"}, dest={"hashCode"}), @Repl(source={"clear"}, dest={"toString"})})
	public void testMoreReplacements() {
		List<String>  l = new LinkedList<String>();
		l.add("1");
		l.add("2");
		l.clear();
	}
	
	@TestSketch
	@Repls(repls = {@Repl(source={"add"}, dest={"remove"}), @Repl(source={"clear"}, dest={"toString"})})
	public void testReplacement_chooseone() {
		List<String> l = new LinkedList<String>();
		l.add("2");
		{/*@ChooseOne*/
			l.add("1");
			l.clear();
		}
		System.out.println(l.size());
	}
	
	@TestSketch
	@Repl(source={"clear", "Date", "getTime", "PERIOD"}, dest={"clone", "Class", "getClass", "DURATION"})
	public void testReplaceQulified() {
		try {
		int PERIOD = 1;
		Date d = Calendar.getInstance().getTime();
		Calendar.getInstance().clear();
		assertEquals(PERIOD - 1, d.getDate()); } catch (Exception e) {}
	}
	
//	@Repl(source={"DurationConverter", "removeDurationConverter", "DURATION_SIZE", "getDurationConverters"},
//    		dest={"PeriodConverter", "removePeriodConverter", "PERIOD_SIZE", "getPeriodConverters"})
//    @TestSketch public void testRemoveDurationConverter1() {
//        try {
//            DurationConverter removed = ConverterManager.getInstance().removeDurationConverter(StringConverter.INSTANCE);
//            assertEquals(StringConverter.INSTANCE, removed);
//            assertEquals(DURATION_SIZE - 1, ConverterManager.getInstance().getDurationConverters().length);
//        } finally {
//            ConverterManager.getInstance().addDurationConverter(StringConverter.INSTANCE);
//        }
//        assertEquals(DURATION_SIZE, ConverterManager.getInstance().getDurationConverters().length);
//    }
}